<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}个人记账应用{% endblock %}</title>
    <!-- 引入 Bootstrap -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入 Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            background-color: #f8f9fa;
        }

        .container {
            margin-top: 50px;
        }

        .navbar {
            margin-bottom: 30px;
        }

        .back-home-btn {
            position: fixed;
            bottom: 20px;
            right: 20px;
        }

        .form-container {
            max-width: 400px;
            /* 限制表单宽度 */
            margin: 0 auto;
            /* 居中对齐 */
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <!-- 导航栏中的应用名称 -->
            <!--        <a class="navbar-brand" href="{{ url_for('home') }}">个人记账应用</a>-->
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <!-- 个人资料页面入口 -->
                    {% if current_user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('profile') }}">个人资料</a>
                    </li>
                    <!-- 返回首页按钮 -->
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">返回首页</a>
                    </li>
                    <!-- 登出按钮 -->
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('logout') }}">登出</a>
                    </li>
                    {% else %}
                    <!-- 如果用户未登录，显示登录链接 -->
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('login') }}">登录</a>
                    </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <!-- 页面内容 -->
    <div class="container">
        <!-- flash 消息 -->
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        <div class="alert alert-{{ messages[0][0] }} mt-3">
            {{ messages[0][1] }}
        </div>
        {% endif %}
        {% endwith %}

        <!-- 主内容块 -->
        {% block content %}{% endblock %}
    </div>

    <!-- 分页导航 -->
    {% if pagination %}
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            {% if pagination.has_prev %}
            <li class="page-item">
                <a class="page-link"
                    href="{{ url_for('view_expenses', page=pagination.prev_num, year=selected_year, month=selected_month) }}">上一页</a>
            </li>
            {% else %}
            <li class="page-item disabled">
                <span class="page-link">上一页</span>
            </li>
            {% endif %}

            {% for page_num in pagination.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
            {% if page_num %}
            {% if page_num == pagination.page %}
            <li class="page-item active">
                <span class="page-link">{{ page_num }}</span>
            </li>
            {% else %}
            <li class="page-item">
                <a class="page-link"
                    href="{{ url_for('view_expenses', page=page_num, year=selected_year, month=selected_month) }}">{{
                    page_num }}</a>
            </li>
            {% endif %}
            {% else %}
            <li class="page-item disabled">
                <span class="page-link">...</span>
            </li>
            {% endif %}
            {% endfor %}

            {% if pagination.has_next %}
            <li class="page-item">
                <a class="page-link"
                    href="{{ url_for('view_expenses', page=pagination.next_num, year=selected_year, month=selected_month) }}">下一页</a>
            </li>
            {% else %}
            <li class="page-item disabled">
                <span class="page-link">下一页</span>
            </li>
            {% endif %}
        </ul>
    </nav>
    {% endif %}

    <!-- 引入 Bootstrap 的 JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
</body>

</html>